package delegate4j;

import com.sun.istack.internal.Nullable;

import java.util.concurrent.FutureTask;

@FunctionalInterface
public interface IAction2<T1, T2> extends IDelegate {
    void invoke(T1 t1, T2 t2) throws Exception;

    default FutureTask<Void> invokeAsync(T1 t1, T2 t2, @Nullable AsyncCallback callback) {
        FutureTask<Void> futureTask = new FutureTask<>(() -> {
            invoke(t1, t2);
            if (callback != null) {
                callback.invoke(this,null);
            }
            return null;
        });
        ASYNC_DELEGATE_THREAD_POOL.submit(futureTask);
        return futureTask;
    }
}
